package jgl.vajra.kingkong.part.vehicle.activity;

import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;

import java.util.Map;

import io.reactivex.Observable;
import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.bean.CommentListBean;
import jgl.vajra.kingkong.bean.OwnerDetailsBean;
import jgl.vajra.kingkong.databinding.ItemCommentPictureItemBindingImpl;
import jgl.vajra.kingkong.databinding.ItemOwnerDetailsEvaluateBinding;
import jgl.vajra.kingkong.manager.IntentManager;
import jgl.vajra.kingkong.part.vehicle.contract.FullExposureContract;
import jgl.vajra.kingkong.part.vehicle.viewModel.FullExposureViewModel;
import jgl.vajra.kingkong.utils.RandomUtils;
import jgl.vajra.kingkong.widget.base.BaseListActivity;
import jgl.vajra.kingkong.widget.bean.BaseListData;
import jgl.vajra.kingkong.widget.databindingadapter.BaseDataBindingDecorator;
import jgl.vajra.kingkong.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.kingkong.widget.interfaces.RefreshRecyclerLoadStatusListener;
import jgl.vajra.kingkong.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.kingkong.widget.recyclerView.RefreshRecyclerNetConfig;
import jgl.vajra.kingkong.widget.retrofithelper.utils.AEACCoder;
import jgl.vajra.kingkong.widget.utils.ToastUtils;

@CreateViewModel(FullExposureViewModel.class)
public class FullExposureActivity extends BaseListActivity<FullExposureViewModel, OwnerDetailsBean.CarListBean>implements FullExposureContract.View {

    private String invitation;

    @Override
    protected String getToolbarTitle() {
        return "全部曝光";
    }

    @Override
    protected RefreshRecyclerNetConfig getRefreshRecyclerNetConfig() {
        return new RefreshRecyclerNetConfig() {
            @Override
            public Observable getNetObservable(Map<String, Object> map, int action) {
                map.put("Authorization", AEACCoder.encrypt(RandomUtils.getRandom()));
                map.put("invitation", invitation);
                return mViewModel.getFullExposureList(map);
            }
        };
    }

    @Override
    protected int getItemLayout() {
        return R.layout.item_owner_details_evaluate;
    }

    @Override
    public void onItemClick(int position, OwnerDetailsBean.CarListBean itemData) {

    }

    @Override
    public void initView() {
        super.initView();

        invitation = getIntent().getStringExtra("invitation");

        mBinding.recyclerView.setIsDataObject(true);
        mBinding.recyclerView.setRefreshLoaderMore(false, false);
        mBinding.recyclerView.setRefreshRecyclerLoadStatusListener(new RefreshRecyclerLoadStatusListener<BaseListData<CommentListBean>>() {
            @Override
            public void onSucceed(BaseListData<CommentListBean> data, int action) {
                mBinding.recyclerView.setRefreshLoaderMore(true, true);


                mBinding.recyclerView.requestNetObjectSuccess(data.data, action);
            }

            @Override
            public void onError(String errorInfo, int errorCode, int action) {
                super.onError(errorInfo, errorCode, action);
//
            }
        });
        mBinding.recyclerView.firstLoad();

        mAdapter.setItemDecorator((BaseDataBindingDecorator<CommentListBean, ItemOwnerDetailsEvaluateBinding>) (binding, position, viewType, data) -> {

            // 不可嵌套滑动
            binding.recyclerViewPicture.setNestedScrollingEnabled(false);
            // 取消head 的 recycleView的焦点
            binding.recyclerViewPicture.setFocusableInTouchMode(false);
            //设置布局管理器

            binding.recyclerViewPicture.setLayoutManager(new GridLayoutManager(this, 3));
            SingleTypeBindingAdapter itemAdapter = new SingleTypeBindingAdapter(this, data.picture, R.layout.item_comment_picture_item);
            binding.recyclerViewPicture.setAdapter(itemAdapter);
            itemAdapter.setItemPresenter(this);

            itemAdapter.setItemDecorator((BaseDataBindingDecorator<String, ItemCommentPictureItemBindingImpl>) (itemBinding, itemPosition, itemViewType, itemData) -> {
                itemBinding.llcView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        IntentManager.toBigImageNetActivity(FullExposureActivity.this,data.picture,itemPosition);
                    }
                });

            });

        });
    }

    @Override
    public void onPicture(int position, String itemData) {

    }
}
